/*
 * @Author: zjj 
 * @Date: 2017-11-30 00:26:30 
 * @Last Modified by: zjj
 * @Last Modified time: 2017-11-30 00:36:18
 * --------------------编译scss文件配置----------------------*
 */
const
  gulp = require('gulp'),
  sass = require('gulp-sass'),
  util = require('gulp-util'),
  notify = require('gulp-notify'),
  autoPrefixer = require('gulp-autoprefixer'),
  argv = require('optimist').argv,
  plumber = require('gulp-plumber'),
  path = require('path');

let
  basePath = path.resolve(__dirname, '..');


gulp.task('sass', cd => (
  gulp.src(path.resolve(basePath, 'src', 'index.scss'))
  .pipe(plumber())
  .pipe(sass({
    //compressed
    //compact
    outputStyle: 'compact'
  }).on('error', sass.logError))
  .pipe(autoPrefixer({
    browsers: ['last 20 versions']
  }))
  .pipe(gulp.dest(path.resolve(basePath, 'dist')))
  .pipe(notify("Found file: <%= file.relative %>!"))
  .on("error", notify.onError(function (error) {
    return "Message to the notifier: " + error.message;
  }))
));

gulp.task('watch', function () {
  gulp.watch(path.join(basePath, 'src/**'), ['sass'])
});


gulp.task('default', argv.watch && ['watch']);